package com.waimai.app.qa.support;

import java.io.File;

import com.jacob.com.LibraryLoader;

import autoitx4java.AutoItX;

/**
 * AutoItX4JavaExecutor Class
 * @author AiHui
 */
public class AutoItX4JavaExecutor {

	/**
	 * @param scriptPath
	 * Method to execute an autoIt exe file\
	 * https://code.google.com/p/autoitx4java/
	 * AutoITX java的实现,后续可根据提供的方法继续封装,但存在不稳定性
	 * @throws InterruptedException 
	 */
	
		public static void main(String args[]) throws InterruptedException {
			
			System.out.println("1111111111");
			File file = new File("lib", "jacob-1.18-M2-x64.dll"); 
			System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
			AutoItX x =new AutoItX();
			  
		  //x.setOption("WinTitleMatchMode", 4);
			x.run("notepad.exe");//这句话不好用
			x.winWaitActive("无标题 - 记事本");
			x.send("1231233");
			 
			x.winWaitActive("ll - 记事本");
			x.winClose("ll - 记事本");   
			x.run("D:\\software\\autoit-v3-setup");
			
			Thread.currentThread().sleep(10000);
			x.winWaitActive("AutoIt v3.3.12.0 Setup");
		  //x.winActivate("AutoIt v3.3.12.0 Setup","Setup Wizard");
			x.controlClick("AutoIt v3.3.12.0 Setup", "&Next >","Button2");
			  
			Thread.currentThread().sleep(2000);
			 
			x.winWaitActive("AutoIt v3.3.12.0 Setup","License Agreement");
			x.winActivate("AutoIt v3.3.12.0 Setup","License Agreement");
			x.controlClick("AutoIt v3.3.12.0 Setup", "I &Agree >","Button2");
			Thread.currentThread().sleep(2000);
			x.winWaitActive("AutoIt v3.3.12.0 Setup","Previous Installation Found");
			x.winActivate("AutoIt v3.3.12.0 Setup","Previous Installation Found");
			x.controlClick("AutoIt v3.3.12.0 Setup", "Cancel","Button3");
			Thread.currentThread().sleep(2000);
			x.winWaitActive("AutoIt v3.3.12.0 Setup","quit");
			x.winActivate("AutoIt v3.3.12.0 Setup","quit");
			x.controlClick("AutoIt v3.3.12.0 Setup", "&Y","Button1");
			System.out.println("1111111111");
			x.winActivate("NUnit 2.6.3 Setup","Setup Wizard");
		    x.winWaitActive("NUnit 2.6.3 Setup","Setup Wizard");  
			 
			x.send("{ALT}n");
			x.winActivate("NUnit 2.6.3 Setup","License Agreement");
			x.winWaitActive("NUnit 2.6.3 Setup","License Agreement");
			x.send("{ALT}a");
			  
			x.winActivate("NUnit 2.6.3 Setup","Choose Setup Type");
			x.winWaitActive("NUnit 2.6.3 Setup","Choose Setup Type");
			x.send("{ALT}t");
			x.send("!n");
			x.winActivate("NUnit 2.6.3 Setup","Ready to install NUnit 2.6.3");
			x.winWaitActive("NUnit 2.6.3 Setup","Ready to install NUnit 2.6.3");
			x.send("{ALT}i");
			Thread.currentThread().sleep(20000);
			x.send("{ALT}n");System.out.println("1111111111");
	}
}
